<?php

namespace app\api\controller;

use \app\common\business\Goods as GoodsBiz;
use app\common\lib\Show;

class Goods extends ApiBase {
    /**
     * 获取轮播图
     * @return \think\response\Json
     */
    public function getRotationChart() {
        $res = (new GoodsBiz())->getRotationChart(5);
        return Show::success($res);
    }

    /**
     * 获取分类下的商品
     * @return \think\response\Json
     */
    public function getGoodsByCategoryId() {
        $categoryId = $this->request->param('category_id', 0, 'intval');
        $limit = $this->request->param('limit', 0, 'intval');

        $res = (new GoodsBiz())->getGoodsByCategoryId($categoryId, $limit);
        return Show::success($res);
    }

    /**
     * 获取商品详情
     * @param $id
     * @return \think\response\Json
     */
    public function detail($id) {
        $skuId = intval($id);
        if ($skuId <= 0) {
            return Show::error('参数错误');
        }
        $res = (new GoodsBiz())->getDetailBySkuId($skuId);
        return Show::success($res);
    }

    //获取商品介绍
    public function getGoodsContent($id) {
        $skuId = intval($id);
        if ($skuId <= 0) {
            return Show::error('参数错误');
        }
        $res = (new GoodsBiz())->getGoodsContent($skuId);
        return Show::success($res);
    }




}